/**
 * zmn 花名册模块-家庭关系和联系人
 * @author tanghongjun
 * @since 2020-05-14 10:56:45
 */
layui.define(['index', 'form', 'table', 'laypage', 'zmnApp', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    var layedit = layui.layedit;
    var laydate = layui.laydate;
    let zmnApp = layui.zmnApp;

    if(json.staffFamily.birthday != null){
        laydate.render({elem: "#birthday", type: "date", value: new Date(json.staffFamily.birthday)});
    }else{
        laydate.render({elem: "#birthday", type: "date"});
    }
    form.render(null, "zmn-form");

    // 提交
    form.on('submit(zmn-form-submit)', function(obj){
        var data = obj.field;
        var url = zmnApp.SYS_BASE_URL +"/staff/stafffamily/addEdit.action";

        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json", dataType: "json", data: JSON.stringify(data),
            success:function(result) {
                if(result.status == 200) {
                    layer.msg("操作成功",{time: 1000},()=>{
                        zmnLayUtil.closeThisIframe(parent);
                        parent.location.reload();
                    });
                } else {
                    layer.msg("操作失败", {"icon": 2});
                }


            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
            }
        })
        return false;
    });

    //点击取消
    $(document).on('click', '#cancel', function () {
        let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    });

    //对外暴露的接口
    exports('plat_stafffamily_detail', {});
});
